#version 330 core

layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;

in vData
{
    vec4 position1;
    vec4 position2;
    vec2 texCoord;
} vertices[];

out fData
{
    vec3 position;
    vec3 normal;
    vec2 texCoord;
} frag;

uniform float u_Blend;

void main (void)
{
    frag.normal = normalize(cross(gl_in[0].gl_Position.xyz - gl_in[1].gl_Position.xyz, gl_in[0].gl_Position.xyz - gl_in[2].gl_Position.xyz));

    for ( int i = 0; i < gl_in.length (); i++ )
    {
        vec4 pos = vertices[i].position1*(1.0-u_Blend) + vertices[i].position2*u_Blend;

        frag.texCoord = vertices[i].texCoord;
        frag.position = pos.xyz;
        gl_Position = pos;
        
        EmitVertex ();
    }

    EndPrimitive ();
}